package io.renren.modules.project.controller;

import java.util.List;
import java.util.Map;

import io.renren.common.annotation.SysLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.project.entity.ProjectScaleEntity;
import io.renren.modules.project.service.ProjectScaleService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-10-05 18:06:33
 */
@RestController
@RequestMapping("/generator/projectscale")
public class ProjectScaleController {
	@Autowired
	private ProjectScaleService projectScaleService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("generator:projectscale:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<ProjectScaleEntity> projectScaleList = projectScaleService.queryList(query);
		int total = projectScaleService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(projectScaleList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") String id){
		ProjectScaleEntity projectScale = projectScaleService.queryObject(id);
		
		return R.ok().put("projectScale", projectScale);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("generator:projectscale:save")
	public R save(@RequestBody ProjectScaleEntity projectScale){
		projectScaleService.save(projectScale);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("generator:projectscale:update")
	public R update(@RequestBody ProjectScaleEntity projectScale){
		projectScaleService.update(projectScale);
		
		return R.ok();
	}

	/**
	 * 保存或者修改
	 */
	@SysLog("新增或修改项目规模")
	@RequestMapping("/updateOrSave")
	public R updateOrSave(@RequestBody ProjectScaleEntity projectScale){
		System.out.println(projectScale);
        projectScaleService.updateOrSave(projectScale);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("generator:projectscale:delete")
	public R delete(@RequestBody String[] ids){
		projectScaleService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
